const { DataTypes, Sequelize } = require("sequelize");
const sequelize = require("./sequelizeBaseConfig.js");

const Menu = sequelize.define(
  "Menu",
  {
    id: {
      type: DataTypes.BIGINT,
      comment: "ID",
      autoIncrement: true, //自增
      primaryKey: true, //主键
    },
    created_at: {
      type: DataTypes.DATE,
      comment: "创建时间",
      defaultValue: Sequelize.literal("CURRENT_TIMESTAMP"), //如果没有设置该字段的值则使用默认
    },
    updated_at: {
      type: DataTypes.DATE,
      comment: "更新时间",
      defaultValue: Sequelize.literal(
        "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
      ),
    },
    name: {
      type: DataTypes.STRING(20),
      allowNull: false,
      comment: "菜单名",
    },
    path: {
      type: DataTypes.STRING(50),
      allowNull: true,
      comment: "菜单路径",
    },
    component: {
      type: DataTypes.STRING(50),
      allowNull: false,
      comment: "组件",
    },
    icon: {
      type: DataTypes.STRING(50),
      allowNull: true,
      comment: "菜单图标",
    },
    parent_id: {
      type: DataTypes.INTEGER,
      allowNull: false,
      comment: "父菜单id",
    },
    order_num: {
      type: DataTypes.TINYINT,
      defaultValue: 0,
      comment: "显示排序",
    },
    is_hidden: {
      type: DataTypes.TINYINT(1),
      defaultValue: 0,
      comment: "是否隐藏(0-否 1-是)",
    },
    keep_alive: {
      type: DataTypes.TINYINT(1),
      defaultValue: 1,
    },
    redirect: {
      type: DataTypes.STRING(50),
      comment: "跳转路径",
    },
  },
  { tableName: "menu", timestamps: false }
);

module.exports = {
  Menu,
};
